<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('车辆维修')" />
    <link rel="stylesheet" href="../../../../../../../../../../../../css/navigation.css">
</head>
<body class="gray-bg">
    <div class="navigation visible-xs-block">
        <ol class="breadcrumb">
            <span> > </span>
            <li><a href="#" onclick="gomain()">主页</a></li>
            <li style="color: black">车辆维修记录</li>
        </ol>
        <div class="aLine"></div>
    </div>
    <div id="container" style="height: 50%"></div>

<!--    <div class="col-sm-12" style="background-color: white">-->
<!--        <button class="btn btn-primary col-xs-6" id="repair"  type="button">维修</button>-->
<!--        <button class="btn btn-default" id="upkeep"  type="button" >保养</button>-->
<!--    </div>-->

    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>车牌号：</label>
                                <input type="text" name="cCarld"/>
                            </li>
<!--                            <li class="select-time">-->
<!--                                <label>登记时间：</label>-->
<!--                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginCTime]"/>-->
<!--                                <span>-</span>-->
<!--                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endCTime]"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>备注：</label>-->
<!--                                <input type="text" name="cRemark"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>金额：</label>-->
<!--                                <input type="text" name="cMoney"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>上传文件：</label>-->
<!--                                <input type="text" name="cData"/>-->
<!--                            </li>-->
                        <li>
                            <label>审批状态：</label>
                            <select name="cStatus" th:with="type=${@dict.getType('car_up')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
                                </option>
                            </select>
                        </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="ruoyi:repair:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="ruoyi:repair:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="ruoyi:repair:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="ruoyi:repair:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>

        </div>
    </div>

    <th:block th:include="include :: footer" />
    <script src="../../../../../../../../../../../../js/breadcrumb.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts-gl/dist/echarts-gl.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts-stat/dist/ecStat.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/dist/extension/dataTool.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/map/js/china.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/map/js/world.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/dist/extension/bmap.min.js"></script>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('ruoyi:repair:edit')}]];
        var removeFlag = [[${@permission.hasPermi('ruoyi:repair:remove')}]];
        var prefix = ctx + "ruoyi/repair";
        var eStatus = [[${@dict.getType('car_up')}]];
        var container = echarts.init(document.getElementById('container'));
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/leadedit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                showColumns: false,
                sortName: 'cTime',
                sortOrder: 'desc',
                modalName: "车辆维修列表",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'cId',
                    title: '记录id',
                    visible: false
                },
                {
                    field: 'cCarld',
                    title: '车牌号'
                },
                {
                    field: 'cTime',
                    title: '维修时间'
                },
                    {
                        // field: 'cMoney',
                        title: '维修金额',
                        formatter: function(value, row, index) {
                            var cMoney = [];
                            if(row.cMoney==null){
                                cMoney.push('￥0');
                                return cMoney.join('')
                            }else{
                                cMoney.push('￥'+row.cMoney);
                                return cMoney.join('');
                            }
                        }
                    },
                    {
                        field: 'cPeople',
                        title: '申请人'
                    },
                    {
                        field: 'cPicture',
                        title: '申请人头像',
                        formatter: function(value, row, index) {
                            return $.table.imageView(value);
                        }
                    },
                    {
                        field: 'cDepa',
                        title: '申请人部门'
                    },
                {
                    field: 'cRemark',
                    title: '备注'
                },
                {
                    field: 'cData',
                    title: '上传文件',
                    formatter: function(value, row, index) {
                        return '<a href="javascript:downloadFile(\''+row.cData+'\')">下载</a>';
                    }
                },
                {
                     field: 'cStatus',
                     title: '审批状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(eStatus, value);
                    }
                },
                    {
                        field: 'cText',
                        title: '审批意见'
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.cStatus ==0){
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="submitApply(\'' + row.cId+ '\')"><i class="fa fa-user"></i> 提交</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.cId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.cId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }else if (row.cStatus ==1){
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="revocations(\'' + row.cId + '\')"><i class="fa fa-user"></i> 撤销</a> ');
                        }else if (row.cStatus ==4){
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="revocations(\'' + row.cId + '\')"><i class="fa fa-user"></i> 撤销</a> ');
                        }else if (row.cStatus ==2){
                            return "申请已通过";
                        }else if(row.cStatus ==3){
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="submitApply(\'' + row.cId + '\')"><i class="fa fa-user"></i> 重新提交</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.cId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="revocation(\'' + row.cId + '\')"><i class="fa fa-user"></i> 撤销</a> ');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function downloadFile(cData) {
            window.location.href=ctx+"common/download/resource?resource="+cData;
        };
        function submitApply(eId) {
            $.modal.confirm("确认要提交申请吗?", function() {
                var url = prefix + "/submitApply";
                var data = { "id": eId};
                $.operate.submit(url, "post", "json", data);
            });
        };
        function over(cId) {

            $.modal.confirm("确认要结束流程吗?", function() {
                var url = prefix + "/over";
                var data = { "id": cId };
                $.operate.submit(url, "post", "json", data);
            });
        };
        function revocations(cId) {

            $.modal.confirm("确认要撤销申请吗?", function () {
                var url = prefix + "/removes";
                var data = {"id": cId};
                $.operate.submit(url, "post", "json", data);
            });
        };
        $("#repair").click(function () {
            location.href="/ruoyi/repair"
        });
        $("#upkeep").click(function () {
            location.href="/ruoyi/upkeep"

        });


        var cCarld=[];
        var cMoney=[];

        var myChart = echarts.init(document.getElementById('container'));

        myChart.setOption({
                // title: {
                //     text: '汽车维修与保养金额',
                //     subtext: ''
                // },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            legend: {
                data: ['维修金额']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: {
                type: 'value',
                boundaryGap: [0, 0.01]
            },
            yAxis: {
                type: 'category',
                data:[]
            },
            series: [
                {
                    name: '维修金额',
                    type: 'bar',
                    data: [],
                    itemStyle: {
                        color: "#ffd85c",
                    }
                },
            ]
        });
        like();
        if (option && typeof option === "object") {
            myChart.setOption(option, true);
        }

        function like(){
            $.ajax({
                url: prefix + "/lists",
                type : "post",
                async : true,
                data : {},
                dataType : "json",
                success : function(data) {

                    for(var i=0; i<data.length; i++){

                        cCarld.push(data[i].cCarld);    //挨个取出车牌号并填入车牌号数组
                    }
                    for(var i=0; i<data.length; i++){
                        cMoney.push(data[i].cMoney);    //挨个取出金额并填入金额数组
                    }
                    myChart.setOption({
                        yAxis: {
                            data: cCarld
                        },
                        series: [{
                            // 根据名字对应到相应的系列
                            name: '维修金额',
                            data: cMoney
                        }]
                    });
                },
                error : function(errorMsg) {
                    //请求失败时执行该函数
                    alert("图表请求数据失败!");
                    myChart.hideLoading();
                }
            });
        }

        //根据窗口大小自适应图表
        window.addEventListener("resize", function () {
            myChart.resize();
        });
    </script>
</body>
</html>